//
//  ViewController.m
//  UI_豆瓣app
//
//  Created by 151129-49宋强 on 15/12/23.
//  Copyright © 2015年 www.lanou3g.com蓝鸥. All rights reserved.
//

#import "ViewController.h"
#import "actModel.h"
#import "MyCell.h"
#import "UIImageView+WebCache.h"
#import "XiangQingViewController.h"

@interface ViewController ()<UITableViewDelegate, UITableViewDataSource>
@property (nonatomic, retain) UITableView *tableView;
@property (nonatomic, retain) NSMutableArray *dateArr;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationItem.title = @"活动";
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"bg_nav"] forBarMetrics:UIBarMetricsDefault];
    self.tableView = [[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStylePlain];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    [self.view addSubview:_tableView];
    
    [self dateHander];
    
    [self.tableView registerClass:[MyCell class] forCellReuseIdentifier:@"cell"];
    _tableView.contentInset = UIEdgeInsetsMake(0, 0, 49, 0);
    
}
- (void)dateHander
{
    self.dateArr = [NSMutableArray array];
    NSString *path = [[NSBundle mainBundle] pathForResource:@"activity" ofType:@"plist"];
    NSArray *Arr = [NSArray arrayWithContentsOfFile:path];
    for (NSDictionary *temp in Arr) {
        actModel *m = [[actModel alloc] init];
        [m setValuesForKeysWithDictionary:temp];
        [_dateArr addObject:m];
    }
    
    
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    XiangQingViewController *xqVC = [[XiangQingViewController alloc] init];
    xqVC.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:xqVC animated:YES];
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 200;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _dateArr.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    MyCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    actModel *m = _dateArr[indexPath.row];
    cell.Label1.text = m.title;
    cell.Label5.text = m.address;
    cell.Label7.text = m.category_name;
    cell.Label9.text = m.wisher_count.stringValue;
    cell.Label9.textColor = [UIColor redColor];
    cell.Label11.text = m.participant_count.stringValue;
    cell.Label11.textColor = [UIColor redColor];
    NSString *str = [m.begin_time substringWithRange:NSMakeRange(5, 11)];
    cell.Label2.text = str;
    NSString *str1 = [m.end_time substringWithRange:NSMakeRange(5, 11)];
    cell.Label4.text = str1;
    [cell.imgView2 sd_setImageWithURL:[NSURL URLWithString:m.image]];

    
    return cell;
}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
